﻿Public Class DRGUGCLASS
    Private UGID = Nothing
    Private UGNAME = Nothing
    Private UGNAME_EN = Nothing
    Private F_FOOD = Nothing
    Private STATUS = Nothing
    Private selectMasdrgug = "SELECT ugid AS 'รหัสวิธีการใช้ยา', ugname AS 'วิธีการใช้ยา(ไทย)', ugname_en AS 'วิธีการใช้ยา(อังกฤษ)', f_food AS 'รับประทาน', `status` AS 'สถานะการเปิดใช้งาน' FROM masdrgug"

    Dim connect As CONDB = CONDB.NewConnection()

    Property UGID_ As String
        Get
            Return UGID
        End Get
        Set(value As String)
            UGID = value
        End Set
    End Property

    Property UGNAME_ As String
        Get
            Return UGNAME
        End Get
        Set(value As String)
            UGNAME = value
        End Set
    End Property

    Property UGNAME_EN_ As String
        Get
            Return UGNAME_EN
        End Get
        Set(value As String)
            UGNAME_EN = value
        End Set
    End Property

    Property F_FOOD_ As Boolean
        Get
            Return F_FOOD
        End Get
        Set(value As Boolean)
            If value = True Then
                F_FOOD = 1
            Else
                F_FOOD = 0
            End If
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrgug_ As String
        Get
            Return selectMasdrgug
        End Get
        Set(value As String)

        End Set
    End Property

    Public Function insertMasdrgug() As Boolean
        If connect.GetTable("SELECT ugid FROM masdrgug WHERE ugname = '" & UGNAME & "'").Rows.Count > 0 Then
            MsgBox("มีข้อมูลการใข้ยานี้อยู่ในระบบแล้ว")
        Else
            Try
                connect = CONDB.NewConnection()

                connect.ExecuteNonQuery("INSERT INTO masdrgug (UGID, UGNAME, UGNAME_EN, F_FOOD, STATUS) VALUES ('" & UGID & "', '" & UGNAME & "', '" & UGNAME_EN & "', '" & F_FOOD & "', '" & STATUS & "')")

                Return True
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
                Return False
            End Try
            connect.Dispose()
        End If
    End Function

    Public Function editMasdrgug() As Boolean
        Try
            connect = CONDB.NewConnection()

            connect.ExecuteNonQuery("UPDATE masdrgug SET UGID = '" & UGID & "', UGNAME = '" & UGNAME & "', UGNAME_EN = '" & UGNAME_EN & "', F_FOOD = '" & F_FOOD & "', STATUS = '" & STATUS & "' WHERE UGID = '" & UGID & "'")

            Return True
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
            Return False
        Finally
            connect.Dispose()
        End Try
    End Function
End Class
